package cloud.seri.gateway.security.oauth2

import javax.servlet.http.Cookie
import javax.servlet.http.HttpServletResponse

/**
 * Holds the access token and refresh token cookies.
 */
class OAuth2Cookies {
    var accessTokenCookie: Cookie? = null
        private set
    var refreshTokenCookie: Cookie? = null
        private set

    fun setCookies(accessTokenCookie: Cookie, refreshTokenCookie: Cookie) {
        this.accessTokenCookie = accessTokenCookie
        this.refreshTokenCookie = refreshTokenCookie
    }

    /**
     * Add the access token and refresh token as cookies to the response after successful authentication.
     *
     * @param response the response to add them to.
     */
    fun addCookiesTo(response: HttpServletResponse) {
        response.addCookie(accessTokenCookie)
        response.addCookie(refreshTokenCookie)
    }
}
